# -*- coding: UTF-8 -*-
from xml.dom.minidom import parse
import xml.dom.minidom
import xlwt
import sys

print("arg = ", sys.argv[1])


if __name__ == '__main__':
    zh = sys.argv[1]
    zh_tree = parse(zh)
    string_list = zh_tree.documentElement.getElementsByTagName("string")

    book = xlwt.Workbook()
    sheet = book.add_sheet('trans')
    row_map = {}
    row = 1
    for str in string_list:
        name = str.getAttribute("name")
        value = str.childNodes[0].data
        row_map[name] = row
        sheet.write(row, 0, name)
        sheet.write(row, 1, value)
        row += 1

    ja = sys.argv[2]
    ja_tree = parse(ja)
    string_list = ja_tree.documentElement.getElementsByTagName("string")

    for str in string_list:
        name = str.getAttribute("name")
        value = str.childNodes[0].data
        row2 = row_map[name]
        sheet.write(row2, 2, value)

    tree = parse(sys.argv[3])
    string_list = tree.documentElement.getElementsByTagName("string")

    error_row = 1
    for str in string_list:
        name = str.getAttribute("name")
        print("name = ", name)
        value = str.childNodes[0].data
        try:
            row = row_map[name]
            sheet.write(row, 3, value)
        except KeyError:
            sheet.write(error_row, 6, name)
            sheet.write(error_row, 7, value)
            error_row += 1

    book.save("trans.xls")
